<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.lmpop.trade.ti_orderinfo.*" %>
<%@page import="com.lmpop.trade.tb_ordergoods.Tb_ordergoodsInfo" %>
<%@page import="java.util.*" %>
<%@page import="com.lmpop.trade.ts_area.*" %>
<%@page import="com.lmpop.trade.tb_commpara.Tb_commparaInfo" %>
<%@page import="com.lmpop.frame.util.PageTools" %>
<%@page import="com.lmpop.trade.ti_attach.Ti_attachInfo" %>
<%@page import="com.lmpop.trade.ti_goods.Ti_goodsInfo" %>
<%@ page import="com.lmpop.frame.util.Config" %>
<%@ page import="com.lmpop.trade.ti_evaluate.Ti_evaluateInfo" %>
<%@page import="com.lmpop.trade.ti_member.*" %>
<%@page import="com.lmpop.trade.ti_company.*" %>
<%@page import="com.lmpop.trade.ti_user.*" %>
<%
	request.setCharacterEncoding("UTF-8");
	Hashtable params = new Hashtable();
	
	String o_order_no ="",o_order_source="",o_email="",o_start_date="",o_end_date="",o_user="",o_consignee="",o_zip_code="";
	String o_area_attr="",o_cellphone="",o_tel="",o_address="",o_shipping_id="",o_pay_id="",o_goods_name="";
	String o_cust="",o_order_state="";


	
	if(request.getParameter("o_address")!=null && !request.getParameter("o_address").equals(""))
	{
      o_address  =request.getParameter("o_address");				
			params.put("o_address",o_address);	
	}			
	
	if(request.getParameter("o_area_attr")!=null && !request.getParameter("o_area_attr").equals(""))
	{
      o_area_attr  =request.getParameter("o_area_attr");				
			params.put("o_area_attr",o_area_attr);	
	}			
	
	if(request.getParameter("o_cellphone")!=null && !request.getParameter("o_cellphone").equals(""))
	{
            o_cellphone  =request.getParameter("o_cellphone");				
			params.put("o_cellphone",o_cellphone);	
	}			
	if(request.getParameter("o_cust")!=null && !request.getParameter("o_cust").equals(""))
	{
            o_cust  =request.getParameter("o_cust");				
			params.put("o_cust",o_cust);	
	}		
	
	if(request.getParameter("o_end_date")!=null && !request.getParameter("o_end_date").equals(""))
	{
      o_end_date  =request.getParameter("o_end_date");				
			params.put("o_end_date",o_end_date);	
	}			
	
	if(request.getParameter("o_goods_name")!=null && !request.getParameter("o_goods_name").equals(""))
	{
      o_goods_name  =request.getParameter("o_goods_name");				
			params.put("o_goods_name",o_goods_name);	
	}			
	if(request.getParameter("o_pay_id")!=null && !request.getParameter("o_pay_id").equals(""))
	{
      o_pay_id  =request.getParameter("o_pay_id");				
			params.put("o_pay_id",o_pay_id);	
	}			
	
	if(request.getParameter("o_shipping_id")!=null && !request.getParameter("o_shipping_id").equals(""))
	{
      o_shipping_id  =request.getParameter("o_shipping_id");				
			params.put("o_shipping_id",o_shipping_id);	
	}		
	

	if(request.getParameter("o_tel")!=null && !request.getParameter("o_tel").equals(""))
	{
      o_tel  =request.getParameter("o_tel");				
			params.put("o_tel",o_tel);	
	}	
	if(request.getParameter("o_user")!=null && !request.getParameter("o_user").equals(""))
	{
      o_user  =request.getParameter("o_user");				
			params.put("o_user",o_user);	
	}	
	if(request.getParameter("o_zip_code")!=null && !request.getParameter("o_zip_code").equals(""))
	{
      o_zip_code  =request.getParameter("o_zip_code");				
			params.put("o_zip_code",o_zip_code);	
	}	

	if(request.getParameter("o_order_no")!=null && !request.getParameter("o_order_no").equals(""))
	{
      o_order_no  =request.getParameter("o_order_no");				
			params.put("o_order_no",o_order_no);	
	}
  
	if(request.getParameter("o_consignee")!=null && !request.getParameter("o_consignee").equals(""))
	{
      o_consignee  =request.getParameter("o_consignee");				
			params.put("o_consignee",o_consignee);	
	}
	if(request.getParameter("o_start_date")!=null && !request.getParameter("o_start_date").equals(""))
	{
		  o_start_date  =request.getParameter("o_start_date");	
			params.put("o_start_date",o_start_date);	
	}
  
 	if(request.getParameter("o_email")!=null && !request.getParameter("o_email").equals(""))
	{
		  o_email  =request.getParameter("o_email");	
			params.put("o_email",o_email);	
	} 

 	if(request.getParameter("o_order_source")!=null && !request.getParameter("o_order_source").equals(""))
	{
      o_order_source  =request.getParameter("o_order_source");				
			params.put("o_order_source",o_order_source);	
	} 

 
	if(request.getParameter("o_order_state")!=null && !request.getParameter("o_order_state").equals(""))
	{
			o_order_state  =request.getParameter("o_order_state");	
			params.put("o_order_state",o_order_state);	
	}
 
	 String session_user_id=""; 
	 if(session.getAttribute("session_user_id")!=null)
	 {
		 session_user_id = session.getAttribute("session_user_id").toString(); 
	 }
	 
	 String session_user_type=""; 
	 if(session.getAttribute("session_user_type")!=null)
	 {
		 session_user_type = session.getAttribute("session_user_type").toString(); 
	 } 

	 Ti_orderinfoInfo ti_orderinfoInfo = new Ti_orderinfoInfo();
	 String iStart = "0";
	 int limit = 5;
	 if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");
	
	  List list = ti_orderinfoInfo.getListByPage(params,Integer.parseInt(iStart),limit);
	  int counter = ti_orderinfoInfo.getCountByObj(params);
		
	String querpage="index.jsp?o_order_no="+o_order_no+"&o_order_source="+o_order_source+"&o_email="+o_email+"&o_start_date="+
	                o_start_date+"&o_end_date="+o_end_date+"&o_user="+o_user+"&o_consignee="+o_consignee+"&o_zip_code="+
	                o_zip_code+"&o_area_attr="+o_area_attr+"&o_cellphone="+o_cellphone+"&o_tel="+o_tel+"&o_address="+o_address+
	                "&o_shipping_id="+o_shipping_id+"&o_pay_id="+o_pay_id+"&o_goods_name="+o_goods_name+"&o_cust="+o_cust+
	                "&o_order_state="+o_order_state+"&iStart=";	
	String para =	"o_order_no="+o_order_no+"&o_order_source="+o_order_source+"&o_email="+o_email+"&o_start_date="+
	                o_start_date+"&o_end_date="+o_end_date+"&o_user="+o_user+"&o_consignee="+o_consignee+"&o_zip_code="+
	                o_zip_code+"&o_area_attr="+o_area_attr+"&o_cellphone="+o_cellphone+"&o_tel="+o_tel+"&o_address="+o_address+
	                "&o_shipping_id="+o_shipping_id+"&o_pay_id="+o_pay_id+"&o_goods_name="+o_goods_name+"&o_cust="+o_cust+
	                "&o_order_state="+o_order_state+"&iStart="+Integer.parseInt(iStart)+"&limit="+limit;                	
	String pageString = new PageTools().getGoogleToolsBar(counter,querpage,Integer.parseInt(iStart),limit);
  
   Tb_commparaInfo tb_commparaInfo = new Tb_commparaInfo();
   String ordersource = tb_commparaInfo.getSelectItem("16","");
										  
   Tb_ordergoodsInfo tb_ordergoodsInfo =new Tb_ordergoodsInfo();
   Ti_attachInfo  ti_attachInfo = new Ti_attachInfo(); 
   String orderStateSelect = tb_commparaInfo.getSelectItem("31","");
   Ti_goodsInfo ti_goodsInfo =new Ti_goodsInfo();
   
    Config configa = new Config();
	String goods_article_path = configa.getString("goods_article_path");
	String company_shop_path = configa.getString("company_shop_path");
    Ti_evaluateInfo evaluateInfo = new Ti_evaluateInfo();
    
  Ti_memberInfo memberInfo = new Ti_memberInfo();
  Ti_companyInfo companyInfo = new Ti_companyInfo();
  Ti_userInfo userInfo =  new Ti_userInfo();
%>
<html>
  <head>
    
   <title>订单管理</title>
	 <link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
	 <script language="javascript" type="text/javascript" src="/program/plugins/calendar/WdatePicker.js"></script>
   <link href="/program/admin/index/css/thickbox.css" rel="stylesheet" type="text/css">
   <script type="text/javascript" src="/js/jquery.js"></script>
   <script type="text/javascript" src="/js/thickbox.js"></script>
   
   <script type="text/javascript" src="js_myorder.js"></script>
   <style>
     .button_s_css{height:18px; width:50px; font-size: 12px; color: #fff; border: 1px #cabca3 solid; 
               background:url(/program/admin/index/images/an_01.gif) repeat-x; cursor:pointer;padding:0 3px 0 3px;}
    </style>



</head>

<body>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td width="90%">
				<h1>订单列表</h1>
			</td>
			<td>
		      <a href="addInfo.jsp"><img src="/program/admin/index/images/post.gif" /></a>
		   </td>
		</tr>
	</table>
	
	<form action="index.jsp" name="indexForm" method="post">
	
	  
	<table width="100%" cellpadding="0" cellspacing="0" class="dl_su">
		<tr>
			<td align="left" >
		 订单编号:<input name="o_order_no" type="text" />
         下单时间:  
          <input name="o_start_date" type="text" id="o_start_date" class="Wdate" value="" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'o_end_date\',{d:-1})}',readOnly:true})" size="15"  width="150px"/>
            -
	     <input name="o_end_date" id="o_end_date" type="text" class="Wdate" value="" onclick="WdatePicker({minDate:'#F{$dp.$D(\'o_start_date\',{d:1})}',readOnly:true})" size="15" width="150px"/>
		              
         订单状态: 
         <select id="o_order_state" name="o_order_state">
          <option value="">请选择</option> 
           <%=orderStateSelect%>
	      </select>						
				
				<input name="searchInfo" type="button" value="查询" onclick="javascript:document.indexForm.submit();"/>	
			</td>
		</tr>
	</table>

	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
		<tr><td><%=pageString %></td></tr>
	</table>
	
	<% 
		int listsize = 0;
		if(list!=null && list.size()>0){
			listsize = list.size();
	%>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
		<tr>
			<td width="90%">
				&nbsp; 	&nbsp;       

  
			</td>
			<td>
				总计:<%=counter %>条			
			</td>
		</tr>
	</table>
	
	
	
	
	
	<table width="100%" cellpadding="1" cellspacing="1" class="listtab" border="0">		
			<tr>	
				<th></th>	 	  	 
		 		<th colspan=2>商品信息</th>	
			 	<th>实付款(元)</th>
		    <th>订单状态</th>			
				<th>操作</th>	  	  
	  	</tr>   

		<% 
		  		for(int i=0;i<list.size();i++){
		  			  Hashtable map = (Hashtable)list.get(i);
		  			  float all_input_price=0;
					  String order_no="",company_area_attr="",area_attr="",all_confirm_money="",all_shipping_fee="",add_time="",all_total_amount="";
					  String cust_id="",order_state="",all_pack_fee="",all_tax_invoice="",pay_id="",user_id="",user_name="",consignee="";
					  if(map.get("order_no")!=null) order_no = map.get("order_no").toString();
					  if(map.get("company_area_attr")!=null) company_area_attr = map.get("company_area_attr").toString();
					  if(map.get("area_attr")!=null) area_attr = map.get("area_attr").toString();
					  if(map.get("all_total_amount")!=null) all_total_amount = map.get("all_total_amount").toString();
					  if(map.get("all_shipping_fee")!=null) all_shipping_fee = map.get("all_shipping_fee").toString();
					  if(map.get("add_time")!=null) add_time = map.get("add_time").toString();
		        if(map.get("order_state")!=null) order_state = map.get("order_state").toString();
					  if(map.get("cust_id")!=null) cust_id = map.get("cust_id").toString();
					  if(map.get("pay_id")!=null) pay_id = map.get("pay_id").toString();
					  if(map.get("user_id")!=null) user_id = map.get("user_id").toString();
					  if(map.get("user_name")!=null) user_name = map.get("user_name").toString();
					  if(map.get("consignee")!=null) consignee = map.get("consignee").toString();
					  if(map.get("all_pack_fee")!=null) all_pack_fee = map.get("all_pack_fee").toString();
					  if(map.get("all_tax_invoice")!=null) all_tax_invoice = map.get("all_tax_invoice").toString();
            if(add_time.length()>19)add_time=add_time.substring(0,19);
					  
					  
					  if(!all_pack_fee.equals("0.00")){
						 all_pack_fee = "(含包装费："+all_pack_fee + ")<br/>";
					  }else{all_pack_fee="";}
					  if(!all_tax_invoice.equals("0.00")){
						 all_tax_invoice = "(含发票税额："+all_tax_invoice + ")<br/>";
					  }else{all_tax_invoice="";}
					  if(!all_shipping_fee.equals("0.00")){
						 all_shipping_fee = "(含运费："+all_shipping_fee + ")<br/>";
					  }else{all_shipping_fee="";}
					 
					  String compnay ="",web_url="#",short_name="";
					  if(!cust_id.equals("") && !cust_id.equals("100000000000000"))
					  {
						   compnay  = memberInfo.getCustNameByPk(cust_id);						   
						   short_name = companyInfo.getShortNameByPk(cust_id);
						   web_url=company_shop_path+short_name;
					  }
					  if (cust_id.equals("100000000000000")) 
					  {
					  	compnay = "自营";
					  	web_url = "/shop.html";
					  }
				    String state_name = tb_commparaInfo.getOneComparaPcode1("31",order_state);
            List  glist = tb_ordergoodsInfo.getListByPk(order_no);					 
 					  boolean isNotEvaluate = evaluateInfo.checkIsnotEvaluate(order_no);
       	  	
		  %>
		
		
		<tr>
				<td colspan=6 style="background:#F7E1D9;">					   
				    订单编号:<%=order_no%>
				    下单时间:<%=add_time%>&nbsp;
				    卖家：<a href="<%=web_url%>" target="_blank">
						<span style="color:#BB8600;">
						<%=compnay%> </span></a>	&nbsp;
					  购买用户：<%=user_name%>&nbsp;&nbsp;收货人：<%=consignee%>
				   
				   </a>
				</td>	     
	  </tr>
	   		
		<tr>		
		<td colspan=3>
		<%
        int checksize =0;        
        if(glist!=null && glist.size()>0){
           checksize = glist.size();    
		       for(int j=0;j<checksize;j++){
					   Hashtable gmap = (Hashtable)glist.get(j);
					   String goods_id="",goods_name="",input_price="0";		  			 
					   String goods_num="0",total_price="0",shop_price="0";		  			  
					  
					    if(gmap.get("goods_id")!=null) goods_id = gmap.get("goods_id").toString();
					  	if(gmap.get("goods_name")!=null) goods_name = gmap.get("goods_name").toString();
					  	if(gmap.get("goods_num")!=null && !gmap.get("goods_num").toString().equals("")) goods_num = gmap.get("goods_num").toString();
					  	if(gmap.get("shop_price")!=null && !gmap.get("shop_price").toString().equals("")) shop_price = gmap.get("shop_price").toString();
						if(gmap.get("input_price")!=null && !gmap.get("input_price").toString().equals("")) input_price = gmap.get("input_price").toString();
						if(gmap.get("total_price")!=null && !gmap.get("total_price").toString().equals("")) total_price = gmap.get("total_price").toString();
						
						all_input_price +=Float.parseFloat(goods_num)*Float.parseFloat(input_price);
						String img_path =  ti_attachInfo.getFilePathByAttachrootid(goods_id);
						if(img_path.equals(""))
						{
							 img_path ="/program/admin/images/cpwu.gif";            
						}
						String g_indate= ti_goodsInfo.getGoodsIn_dateById(goods_id);
						if(g_indate.length()>10)g_indate=g_indate.substring(0,10);
						String infoUrl = "updateInfo.jsp?order_no="+order_no;



		
		%>
		
		<table width="100%" cellpadding="0" cellspacing="0" border="0">
		
		<tr>
		  
		  	<td width="10%">
		  	    <a href="<%=infoUrl%>" target="_blank"><img src="<%=img_path%>" border="0" width="50" height="50"  style="border:1px solid #cecece;"/></a>		  		
		  	</td>
		  	
		  	<td>
		  		<span style="color:#303A43;">名称:</span>		  		
		  		<a href="<%=infoUrl%>" target="_blank"><span style="color:#751D19;font-size:14px;font-weight:bold"><%=goods_name%></span></a>	
		  		<div style="margin-top:8px;"></div>
                <span style="color:#303A43;">商品单价:</span>		  		
		  		<span style="color:#666666;">￥<b><%=shop_price%></b></span>	
                <span style="color:#303A43;">&nbsp;购买数量:</span>		  		
		  		<span style="color:#666666;"><%=goods_num%></span>					
		   </td>
			
	     </tr>
		</table>
		  <%
		  		}
		     }
		  %>
		    </td>
			 
			<td cellspan=<%=i+1%>>
				<span style="font-size:16px;font-weight:bold;color:#F52D0A"><%=all_total_amount%></span>
				<div style="margin-top:4px;color:#808080">
				
				<%=all_shipping_fee%>
			    <%=all_pack_fee%>
				<%=all_tax_invoice%>
				
				</div>

			</td>
			
			<td cellspan=<%=i+1%>>
		  	<%=state_name%>
			<div style="margin-top:8px;"></div>
			<a href="updateInfo.jsp?order_no=<%=order_no%>&<%=para%>" target="_blank"><span style="color:#3366CC;">订单详情</span></a>
			</td>
		   
		   <td cellspan=<%=i+1%>>
		  	
				   	<%
						if(!order_state.equals("3") && !order_state.equals("4")){
					%>
                   
						<a href="javascript:checkstate('<%=order_no%>','5590','4');" >
							<div style="background:url(/program/admin/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">作废</div>
						</a>
						
					<%}%>
					
                      	<div style="margin-top:4px;"></div>


				   <%
						if(order_state.equals("1") || order_state.equals("6") ){
					%>
							<div id="div<%=i %><%=i %>" >
				  		<a href="javascript:alterState('<%=cust_id %>','<%=order_no %>','<%=all_input_price%>',<%=i %>,'<%=area_attr %>')">
						<div style="background:url(/program/admin/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">卖家发货</div>
						</a>    
				 </div>
			  	 <div id="div<%=i %>" style="display: none">
				  	 配送单：<input type="text" name="peisong_no<%=i %>" id="peisong_no<%=i %>" /><br/>
				  	 配送公司：<input type="text" name="peisong_company<%=i %>" id="peisong_company<%=i %>" />
			  	 </div>
					<%
						}
						
					%>
					
					<%
						if(order_state.equals("0")  && pay_id.equals("0")){
					%>
			
		  			 <center>等待买家付款</center>
  						            
				   <%
				   } 
				   %>
				   
				   	<%
						if(order_state.equals("2")){
					%>
			
  						<a href="/doTradeReg.do?order_no=<%=order_no%>&order_state=3&bpm_id=5590">
							<div style="background:url(/program/admin/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">完成交易</div>
						</a>                 
				   <%
				   } 
				   %>
					
					<%
						if(order_state.equals("3") && isNotEvaluate){
					%>
					  <center>等待买家评价</center>
					<%
						}
					%>
					
					<%
						if(order_state.equals("3") && !isNotEvaluate){
					%>
					     <center> <span style="color:#3366CC;">买家已评价</span></center>
					<%
						}
					%>
					<%
					if(order_state.equals("4")){%>
						<a href="/doTradeReg.do?order_no=<%=order_no%>&order_state=0&bpm_id=5590">
							<div style="background:url(/program/admin/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">恢复</div>
						</a>
						<a href="javascript:deleteorder('<%=order_no%>','0213');" >
							<div style="background:url(/program/admin/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;" >删除</div>
						</a>
					<%}
					
					%>
			
	</td>


		  </tr> 
		<%  
		  }
		  
		  %>		
		
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
		<tr>
			<td width="90%">
				&nbsp; 	&nbsp;       
       
	   
	   
			</td>
			<td>
				总计:<%=counter %>条			
			</td>
		</tr>
	</table>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
		<tr><td><%=pageString %></td></tr>
	</table>
	
	<%
		 }
	%>
	
	  <input type="hidden" name="listsize" id="listsize" value="<%=listsize %>" />
	  <input type="hidden" name="pkid" id="pkid" value="" />
	  <input type="hidden" name="bpm_id" id="bpm_id" value="" />
	
                                                                  
    
   	  
	  
	  </form>
	  	<form action="/doTradeReg.do" method="post" name="bpmForm">
			<input type="hidden" name="bpm_id" id="bpm_id" value="5355" />			
			<input type="hidden" name="user_id" id="user_id" value="<%=session_user_id%>" />
			<input type="hidden" name="trade_type" id="trade_type" value="5355" />
			<input type="hidden" name="order_state" id="order_state" value="2" />
			
			<input type="hidden" name="order_no" id="order_no" value="" />
			<input type="hidden" name="peisong_no" id="peisong_no" value="" />
			<input type="hidden" name="peisong_company" id="peisong_company" value="" />
			
			<input type="hidden" name="product_code" id="product_code" value="G" />
			<input type="hidden" name="biz_id" id="biz_id" value="" />
			<input type="hidden" name="area_attr" id="area_attr" value="" />
			<input type="hidden" name="agent_product_code" id="agent_product_code" value="" />
			<input type="hidden" name="income_ratio" id="income_ratio" value="" />
			<input type="hidden" name="income_num" id="income_num" value="" />
		</form>
</body>

</html>
